********************************************************************************
******"Macroprudential Regulation, Quantitative Easing, and Bank Lending"*******
********************************************************************************
global y "lncdisbur_w199"
global regcommands ", compact pool(2) absorb(bankid2 borrowerid#time) vce(cluster bankid2)"

clear *
**# Bookmark (input)
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans, case(lower)
run RO_creditregister tm(2014m6) tm(2015m6) 0
keep bankid borrowerid time disbur

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2015, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2014m12, keepus(e12 e13 exlnassets excashas)
keep if _merge==3
drop _merge

**# Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2015, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2014m7)&time<=tm(2015m6)
run RO_tdummies 2015 12

keep bankid borrowerid time e12 e13 excashas exlnassets lncrefin lncdisbur dT1-dT12

**# Bookmark (input)
append using $inputdirectory/INB_core2019temp, keep(bankid borrowerid time e12 e13 excashas exlnassets lncrefin lncdisbur dT1-dT12)

run RO_tdintera 12 "excashas exlnassets e12 e13"

gen bankid2=bankid
replace bankid2=bankid+99999 if time>=tm(2019m3)
gen p2019=(time>=tm(2019m3))
foreach x of numlist 1 2 3 4 5 7 8 9 10 11 12 {
foreach var of varlist dT`x'e13 dT`x'e12 dT`x'exlnasset dT`x'excashas {
gen `var'p2019=`var'*p2019
}
}
gen lncrefinp2019=lncrefin*p2019

winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)

**# Bookmark (output - columns 1-2-3)
cd $outputdirectory
est clear
reghdfe $y dT*e12 dT*e12p2019 dT*e13 dT*exlnassets dT*excashas lncrefin $regcommands
est save TABIXA_C123
reghdfe $y dT*e12 dT*e12p2019 dT*e13 dT*exlnassets dT*exlnassetsp2019 dT*excashas dT*excashasp2019 lncrefin lncrefinp2019 $regcommands
est save TABIXA_C123, append
reghdfe $y dT*e12 dT*e12p2019 dT*e13 dT*e13p2019  dT*exlnassets dT*exlnassetsp2019 dT*excashas dT*excashasp2019 lncrefin lncrefinp2019 $regcommands
est save TABIXA_C123, append
cd ..

